package com.smart.controller;

import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.github.pagehelper.PageInfo;
import com.smart.model.request.ManageUserRegistrationRequest;
import com.smart.model.request.ProjectRequest;
import com.smart.model.vo.ProjectVO;
import com.smart.model.vo.SuperviseManageCountVO;
import com.smart.service.ManageUserRegistrationService;
import com.smart.model.vo.ManageUserRegistrationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/registration")
@Api(value = "项目人员管理模块", tags = {"项目人员管理模块"})
public class ManageUserRegistrationController {

    @Autowired
    private ManageUserRegistrationService manageUserRegistrationService;

    @WebAccess(login = true)
    @ApiOperation(value = "离场前校验是否为在场人员", httpMethod = "POST")
    @PostMapping("/exitVerify")
    public WebResponse<ManageUserRegistrationVO> exitVerify(@RequestParam("idCard") String idCard,@RequestParam("projectId") Long projectId) {
        return WebResponse.build(manageUserRegistrationService.exitVerify(idCard,projectId));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "是否已进场校验", httpMethod = "POST")
    @PostMapping("/entranceVerify")
    public WebResponse<ManageUserRegistrationVO> entranceVerify(@RequestParam("idCard") String idCard,@RequestParam("projectId") Long projectId) {
        return WebResponse.build(manageUserRegistrationService.entranceVerify(idCard,projectId));
    }

    @WebAccess(login = true)
    @ApiOperation("云监管、云管理项目人员管理查询")
    @PostMapping("/supervisePageQueryManage")
    public WebResponse<PageInfo> supervisePageQueryManage(@RequestBody ProjectRequest request) {
        return WebResponse.build(manageUserRegistrationService.supervisePageQueryManage(request));
    }

    @WebAccess(login = true)
    @ApiOperation("云监管项目人员管理查询统计")
    @PostMapping("/supervisePageQueryManageCount")
    public WebResponse<SuperviseManageCountVO> supervisePageQueryManageCount(@RequestBody ProjectRequest request) {
        return WebResponse.build(manageUserRegistrationService.supervisePageQueryManageCount(request));
    }

    @WebAccess(login = true)
    @ApiOperation("云监管、云管理项目人员进出场记录查询")
    @PostMapping("/supervisePageQueryRecords")
    public WebResponse<PageInfo<List<ManageUserRegistrationVO>>> supervisePageQueryRecords(@SortDefault(sort = "mur.entrance_time",direction = Sort.Direction.DESC) Pageable pageable,
                                                                                           @RequestBody ManageUserRegistrationRequest request) {
        return WebResponse.build(manageUserRegistrationService.supervisePageQueryRecords(request,pageable));
    }

    @WebAccess(login = true)
    @ApiOperation("云服务项目人员进出场记录查询")
    @PostMapping("/supervisePageLists")
    public WebResponse<PageInfo<List<ManageUserRegistrationVO>>> supervisePageLists(@SortDefault(sort = "entrance_time",direction = Sort.Direction.DESC) Pageable pageable,
                                                                                           @RequestBody ManageUserRegistrationRequest request) {
        return WebResponse.build(manageUserRegistrationService.supervisePageLists(request,pageable));
    }

    @WebAccess(login = true)
    @ApiOperation("云服务平台项目人员管理查询")
    @PostMapping("/cloudPageQueryManage")
    public WebResponse<PageInfo<List<ManageUserRegistrationVO>>> cloudPageQueryManage(@SortDefault(sort = "mur.entrance_time",direction = Sort.Direction.DESC) Pageable pageable,
                                                                     @RequestBody ManageUserRegistrationRequest request) {
        return WebResponse.build(manageUserRegistrationService.cloudPageQueryManage(request,pageable));
    }

    @WebAccess(login = true)
    @ApiOperation("人员进场信息保存")
    @PostMapping("/entrance")
    public WebResponse<Object> entrance(@Valid @RequestBody ManageUserRegistrationRequest request) {
        return WebResponse.build(manageUserRegistrationService.entrance(request));
    }

    @WebAccess(login = true)
    @ApiOperation("人员离场信息保存")
    @PostMapping("/exit")
    public WebResponse<Object> exit(@Valid @RequestBody ManageUserRegistrationRequest request) {
        return WebResponse.build(manageUserRegistrationService.exit(request));
    }

}
